<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Server-Sent Events Example</title>
</head>

<body>
<div id="messages"></div>
<script>
    const eventSource = new EventSource('/sse');

    eventSource.onmessage = function (event) {
        const messagesDiv = document.getElementById('messages');
        const newMessage = document.createElement('p');
        newMessage.textContent = `Received: ${event.data}`;
        messagesDiv.appendChild(newMessage);
    };

    eventSource.onerror = function (error) {
        console.error('EventSource failed:', error);
        eventSource.close();
    };
</script>
</body>

</html>
